<?php
/**
 * User: zyj
 * Date: 2019/11/5
 */

namespace app\manage\logic;



use app\manage\model\AuthGroup;
use think\facade\Request;

class Role extends Base
{
    /**
     * @return array
     * @throws \think\db\exception\DbException
     * @author zyj<535985755@qq.com>
     * Date: 2019/11/7
     */
    public function getRoleList()
    {
        $page = input("page","1","int");
        $limit = input("limit","10","int");
        $title = input("title","","string");
        $map[] = ['status','=','0'];
        if (isset($title)) {
            $map[] = ['title', 'like', '%' . $title . '%'];
        }
        $list =AuthGroup::where($map)->paginate(['list_rows' => $limit, 'page' =>$page]);
        return ['code'=>0,'msg'=>'get info success','count'=>$list->total(),'data'=>$list->getCollection()];
    }
    /**
     * @return array
     * @throws \think\db\exception\DbException
     * @author zyj<535985755@qq.com>
     * Date: 2019/11/7
     */
    public function getRoleData()
    {
        $data =AuthGroup::where('status',"=","0")->select();
        return $data;
    }

    /**
     * 添加或编辑
     * @param $data
     * @return bool
     * @author zyj<535985755@qq.com>
     * Date: 2019/11/7
     */
    public function addRole($data)
    {
        $authGroup = new AuthGroup();
        if(!empty($data['id'])){
            $authGroup = AuthGroup::findOrEmpty($data['id']);
            if($authGroup->isEmpty()){
                return false;
            }
        }
        $info = $authGroup->save($data);
        return $info;
    }

    /**
     * 删除
     * @author zyj<535985755@qq.com>
     * Date: 2019/11/8
     */
    public function delRole($data)
    {
        $authGroup = AuthGroup::findOrEmpty($data['id']);
        if($authGroup->isEmpty()){
            return false;
        }
        $info = $authGroup->save(['status'=>"9"]);
        return $info;
    }


    /**
     * 获取组菜单
     * @param $data
     * @return array|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author zyj<535985755@qq.com>
     * Date: 2019/11/8
     */
    public function getGroupMenu($data)
    {
        $map[] = ['id', '=', $data['id']];
        $groupData = AuthGroup::where($map)->find();
        return $groupData;
    }

}